# PLOTS RESPECTABILITY POLITICS
# ALAN YAN
# SEPTEMBER 22, 2020

#### SETUP ####
#clear environment
rm(list = ls())

#load libraries
library(pacman)
p_load(tidyverse,
       stargazer)

#### LOAD DATA ####
#load data
dt <- read_rds("01-data/clean-data")
nrow(dt)
dt %>%
  drop_na(r_sex,
          r_edu,
          r_pid,
          r_age,
          r_ideology) -> dt

#### MAKE TABLE ####
#### *DUMMYING CATEGORICAL VARIBLES ####
#Sex
for(i in unique(dt$r_sex)) {
  dt[i] <- ifelse(dt$r_sex == i, 1, 0)
}

#Education
for(i in unique(dt$r_edu)) {
  dt[i] <- ifelse(dt$r_edu == i, 1, 0)
}

#PID
for(i in unique(dt$r_pid)) {
  dt[i] <- ifelse(dt$r_pid == i, 1, 0)
}

#Age
for(i in unique(dt$r_age)) {
  dt[i] <- ifelse(dt$r_age == i, 1, 0)
}

#South
for(i in unique(dt$r_south)) {
  dt[i] <- ifelse(dt$r_south == i, 1, 0)
}

#Ideology
for(i in unique(dt$r_ideology)) {
  dt[i] <- ifelse(dt$r_ideology == i, 1, 0)
}

covariates <- names(dt)[83:116]

dt %>%
  select(covariates) %>%
  as.data.frame() %>%
  stargazer(., summary = TRUE,
            summary.stat = c("mean", "sd", "n"))
